<?php

/**
 * --------------------------------------
 * PHPエラーの表示
 * --------------------------------------
 */
if(!defined('DEBUG_MODE')){ define('DEBUG_MODE', $aKEINOS_ENVIRONMENT['debug_mode'] );}

/**
 * --------------------------------------
 * include_pathのセパレーター設定
 * --------------------------------------
 */
if (!defined('PATH_SEPARATOR')) {
    if ($aKEINOS_ENVIRONMENT['IS_WINDOWS']) {
        define('PATH_SEPARATOR', ';');
    } else {
        define('PATH_SEPARATOR', ':');
    }
}
/**
 * --------------------------------------
 * include_pathの設定
 * --------------------------------------
 */
$sInclude_path  = ini_get('include_path');
$aInclude       = explode(PATH_SEPARATOR,$sInclude_path);

//KEINOS functionsを利用するのに必要なパスを追加
if(!Empty($aRealPath['lib_dir']))       { $aInclude[] = $aRealPath['lib_dir']; }
if(!Empty($aRealPath['keinos_lib_dir'])){ $aInclude[] = $aRealPath['keinos_lib_dir']; }

//ユーザーインストールのPEARがあったら同時にinclude_pathに加える
$aPathList      = array(
        'PEAR',
        'PEAR/PEAR',
        'PEAR/PEAR/PEAR',
        'PEAR/PEAR/PEAR/PEAR',
        'KEINOS/PEAR',
        'KEINOS/PEAR/PEAR',
        'KEINOS/PEAR/PEAR/PEAR',
    );
// 手動でPEARがあったらパスに含める
foreach($aPathList as $sKey=>$sPathToPearConf){
    $sPath = $aRealPath['lib_dir'] . $sPathToPearConf;
    $sPath_full = $sPath . DIRECTORY_SEPARATOR . "pear.conf";
    if( file_exists($sPath_full)){
        //PEARのインストール時に作成されるconfファイルの読み込み
        $sConf = file_get_contents($sPath_full);
        $sConf = preg_replace('/^#[\w\W]+\n/i','',$sConf,1);
        $aConf = unserialize( trim($sConf) );
        //confファイルに記載されいてるパスを登録
        $aInclude[] = $aConf['php_dir'];
        $aKEINOS_ENVIRONMENT['include_path_pear'] = $aConf['php_dir'];
    }
}

//include_pathの同じ項目を削除
$aInclude = array_unique($aInclude);
//include_path用のパス・データの生成
$sInclude_path = "";
foreach($aInclude as $key=>$sItem){
    $sInclude_path .= (Empty($sItem)) ? "" : $sItem . PATH_SEPARATOR;
}

ini_set('include_path',$sInclude_path);
unset($sPath,$sPath_full,$aInclude,$sInclude_path,$sConf,$aConf);


/**
 * --------------------------------------
 *   initialize.incを呼び出したスクリプ
 *   トと同じ場所にディレクトリがあった
 *   場合はそれを使う
 * --------------------------------------
 */
if( dir_exists($aKEINOS_ENVIRONMENT['template_dir'],"./") ){
    $aRealPath['template_dir'] = realpath("./{$aKEINOS_ENVIRONMENT['template_dir']}/");
}

if(!defined('ROOT_LIB_DIR'))        { define('ROOT_LIB_DIR',        $aRealPath['lib_dir'] );}
if(!defined('KEINOS_LIB_DIR'))      { define('KEINOS_LIB_DIR',      $aRealPath['keinos_lib_dir'] );}
if(!defined('KEINOS_DATA_DIR'))     { define('KEINOS_DATA_DIR',     $aRealPath['data_dir'] );}
if(!defined('KEINOS_TEMPLATE_DIR')) { define('KEINOS_TEMPLATE_DIR', $aRealPath['template_dir'] );}
if(!defined('KEINOS_COMPILE_DIR'))  { define('KEINOS_COMPILE_DIR',  $aRealPath['compile_dir'] );}
if(!defined('KEINOS_CACHE_DIR'))    { define('KEINOS_CACHE_DIR',    $aRealPath['cache_dir'] );}

session_save_path($aRealPath['cache_dir']); 

//互換
if(!defined('DIR_DATA')) { define('DIR_DATA', KEINOS_DATA_DIR );}


unset($aKEINOS_ENVIRONMENT);
unset($aRealPath);

?>